function getDomain(url) {
    const my_reg = /https?:\/{2}[^\/]*\//;
    const result = my_reg.exec(url);
    console.log(result);
    let domain = url;
    if (result != null) {
        domain = result[0];
    }
    return domain;
}

const url = "http://www.example.test.com";
const domain = getDomain(url);
console.log(domain);